package com.tao.config;

import com.tao.properties.AliOssProperties;
import com.tao.utils.ALiOSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfiguration {

    //ALIOSSUtils中的属性理论上为静态属性，将其配置在配置文件中，若是随用随Autowired，还需Autowired ALiOssProperties
    // 每次用到该工具类都要注入两个，像这种要多次用到的类，并且创造比较麻烦，就统一在配置文件中创造

    @Autowired
    AliOssProperties aliOssProperties;

    @Bean
    @ConditionalOnBean
    public ALiOSSUtil aLiOSSUtil(){
        log.info("开始注册阿里OSS工具类");
        return new ALiOSSUtil(aliOssProperties.getEndPoint(), aliOssProperties.getAccessKeyId(), aliOssProperties.getAccessKeySecret(), aliOssProperties.getBucketName());
    }
}
